package com.example.chapter4.bean;


import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class ServletConfigText extends HttpServlet {
    private ServletConfig config;
    public ServletConfigText(){
        super();
    }
    @Override
    public void destroy() {
        super.destroy();
    }
    @Override
    public void init(ServletConfig config) throws SecurityException{
        super.init(config);
        this.config = config;
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
            SecurityException, IOException {
        response.charset= this.config.getInitParameter("charset");
        request.setCharacterEncoding("charset");
        request.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<HEAD><TITLE>ServletConfig</TITLE></HEAD>");
        out.println("<BODY>");
        out.println("获取InitParamServlet的初始化参数\"encoding\"的字符串值："+charset);
        out.println("</BODY>");
        out.println("</html>");
        out.flush();
        out.close();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        doPost(request, response);
    }
}
